﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using EBA.Linq;

namespace EBA.Data
{
    public class LinqRepository<TEntity, TContract> : IRepository<TContract> where TEntity :class, TContract, new()
    {
        public LinqRepository(Table<TEntity> table)
        {
            this.Table = table;
        }

        Table<TEntity> Table;

        public TContract NewEntity()
        {
            return new TEntity();
        }

        public void Add(TContract entity)
        {
            this.Table.InsertOnSubmit((TEntity)entity);
        }

        public void Delete(TContract entity)
        {
            this.Table.DeleteOnSubmit((TEntity)entity);
        }

        public void DeleteAll(IEnumerable<TContract> entities)
        {
            this.Table.DeleteAllOnSubmit(entities.OfType<TEntity>());
        }

      

        public int DeleteAll(System.Linq.Expressions.Expression<Func<TContract, bool>> filter)
        {
            throw new NotImplementedException();
        }


        public int UpdateAll(System.Linq.Expressions.Expression<Func<TContract, bool>> filter, System.Linq.Expressions.Expression<Func<TContract, object>> evaluator)
        {
            throw new NotImplementedException();
        }


        public IQueryable<TContract> AsQuerybale
        {
            get { return this.Table.AsQueryable(); }
        }


        public void WithWhere(string predicate)
        {
            throw new NotImplementedException();
        }


        public IRepository<TContract> CreateTransient()
        {
            throw new NotImplementedException();
        }


        ITransientRepository<TContract> IRepository<TContract>.CreateTransient()
        {
            throw new NotImplementedException();
        }
    }
}
